import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * service - 期间定义
 * @date: 2018-7-10


 */
import request from 'utils/request';
import { CPAAS_PLATFORM } from 'utils/config';
import { getCurrentOrganizationId, isTenantRoleLevel, parseParameters } from 'utils/utils';
/**
 * 请求API前缀
 * @type {string}
 */

var prefix = "".concat(CPAAS_PLATFORM, "/v1").concat(isTenantRoleLevel() ? "/".concat(getCurrentOrganizationId()) : '');
/**
 * 平台级会计期查询
 * @async
 * @function searchHeader
 * @param {object} params - 查询条件
 * @param {?string} params.periodSetName - 会计期名称
 * @param {?string} params.periodSetCode - 会计期编码
 * @param {!object} params.page - 分页参数
 * @returns {object} fetch Promise
 */

export function searchHeader(_x) {
  return _searchHeader.apply(this, arguments);
}
/**
 * 平台级期间查询
 * @async
 * @function searchLine
 * @param {Object} params - 查询条件
 * @param {?string} params.periodName - 期间
 * @param {?string} params.periodYear - 年
 * @param {?string} params.periodSetCode - 会计期编码
 * @param {!object} params.page - 分页参数
 * @returns {Object} fetch Promise
 */

function _searchHeader() {
  _searchHeader = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var param;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            param = parseParameters(params);
            return _context.abrupt("return", request("".concat(prefix, "/period-sets"), {
              method: 'GET',
              query: param
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _searchHeader.apply(this, arguments);
}

export function searchLine(_x2) {
  return _searchLine.apply(this, arguments);
}
/**
 * 会计期保存
 * @async
 * @function savePeriodHeader
 * @param {Object} params - 请求参数
 * @param {Object[]} param.saveData - 保存数据列表
 * @param {?number} param.saveData[].periodSetId - 会计期Id
 * @param {!string} param.saveData[].periodSetCode - 会计期编码
 * @param {!string} param.saveData[].periodSetName - 会计期名称
 * @param {?number} [param.saveData[].enabledFlag = 1] - 启用标记
 * @param {?number} param.saveData[].periodTotalCount - 期间总数
 * @param {?string} param.saveData[].refPeriodSetId - 引用期间Id
 * @param {?number} [param.saveData[].tenantId = 0] - 租户Id
 * @param {?number} param.saveData[].objectVersionNumber - 版本号
 * @returns {Object} fetch Promise
 */

function _searchLine() {
  _searchLine = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    var param;
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            param = parseParameters(params);
            return _context2.abrupt("return", request("".concat(prefix, "/period-sets/periods"), {
              method: 'GET',
              query: param
            }));

          case 2:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _searchLine.apply(this, arguments);
}

export function savePeriodHeader(_x3) {
  return _savePeriodHeader.apply(this, arguments);
}
/**
 * 期间总是查询
 * @async
 * @function searchPeriodRule
 * @param {Object} params - 查询参数
 * @param {!number} params.periodSetId - 会计期id
 * @returns {Object} fetch Promise
 */

function _savePeriodHeader() {
  _savePeriodHeader = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(prefix, "/period-sets"), {
              method: 'POST',
              body: _toConsumableArray(params)
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _savePeriodHeader.apply(this, arguments);
}

export function searchPeriodRule(_x4) {
  return _searchPeriodRule.apply(this, arguments);
}
/**
 * 期间维护保存
 * @async
 * @function savePeriod
 * @param {Object} params - 保存参数
 * @param {!number} params.periodSetId - 会计期id
 * @param {Object[]} param.data - 保存数据列表
 * @param {!number} param.data[].periodSetId - 会计期id
 * @param {!string} param.data[].periodName - 期间名称
 * @param {!string} param.data[].orderSeq - 序号
 * @param {?number} param.data[].periodId- 期间Id
 * @param {?number} [param.data[].enabledFlag = 1]  - 启用标记
 * @param {?number} param.data[].periodQuarter - 季度
 * @param {?string} param.data[].periodYear - 年
 * @param {?string} param.data[].endDate - 截止时间
 * @param {?string} param.data[].startDate - 起始时间
 * @returns {Object} fetch Promise
 */

function _searchPeriodRule() {
  _searchPeriodRule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(prefix, "/period-sets/").concat(params.periodSetId, "/periods"), {
              method: 'GET'
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _searchPeriodRule.apply(this, arguments);
}

export function savePeriod(_x5) {
  return _savePeriod.apply(this, arguments);
}

function _savePeriod() {
  _savePeriod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            return _context5.abrupt("return", request("".concat(prefix, "/period-sets/").concat(params.periodSetId, "/periods"), {
              method: 'POST',
              body: _toConsumableArray(params.data)
            }));

          case 1:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _savePeriod.apply(this, arguments);
}